/*
 * @Description: 配置文件
 * @Author: yilingsj（315800015@qq.com）
 * @Date: 2020-08-03 14:26:25
 * @LastEditors: yilingsj（315800015@qq.com）
 * @LastEditTime: 2021-06-26 11:32:59
 */
const vConsolePlugin = require('vconsole-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const productionGzipExtensions = ['js', 'css']
const TransformPages = require('uni-read-pages')
const { webpack } = new TransformPages()

const isDevelopment = process.env.NODE_ENV !== 'production'
const pluginsDev = [
  new vConsolePlugin({
    filter: [],
    enable: isDevelopment, // 生产环境去掉vconsole调试器
  }),
]
console.log('环境', isDevelopment, process.env.NODE_ENV)
module.exports = {
  configureWebpack: (config) => {
    config.plugins = [
      ...config.plugins,
      //...pluginsDev,
      new BundleAnalyzerPlugin({ analyzerPort: 8989 }),
      // 自动构建路由表 https://hhyang.cn/v2/tutorial/rgRoutes.html#安装
      new webpack.DefinePlugin({
        ROUTES: webpack.DefinePlugin.runtimeValue(() => {
          const tfPages = new TransformPages({
            includes: ['path', 'name', 'meta', 'aliasPath'],
          })
          return JSON.stringify(tfPages.routes)
        }, true),
      }),
    ]
  },
  css: {
    sourceMap: isDevelopment,
  },
}
